Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • forval i = 1/2 skip a few, 99/100 { ...

    Hi all,

    Let's say I want to loop over values 1 to 100 using forval, but I want to skip a few in between. What is the best way to do this? Thanks,

    Alex

  • #2
    Code:
    forval i=1/100 {
      if inlist(`i',7,17,37) continue
    
      // ... do my stuff with `i' here
    
    }
    see help for continue

    Comment


    • #3
      Originally posted by Sergiy Radyakin View Post
      Code:
      forval i=1/100 {
      if inlist(`i',7,17,37) continue
      
      // ... do my stuff with `i' here
      
      }
      see help for continue
      Thanks! I have also just found out about the inrange function, which can also be used (and may avoid typing out a long list of numbers in some situations).

      Comment


      • #4
        The FAQ https://www.stata.com/support/faqs/d...-with-foreach/ may also help.

        Comment

        Working...
        X